//
//  RangeExample.swift
//  SwiftTest
//
//  Created by bym on 2019/8/8.
//  Copyright © 2019 ZZ. All rights reserved.
//

import UIKit

class RangeExample: NSObject {
	
	override init() {
		super.init()
		property()
	}

	func initMethod() {
		//快捷方式
		let a : Range = 0..<5
		ZZLog(a)
		
		//不安全初始化 一定要用可选绑定
		let b = Range.init(uncheckedBounds: (1,2))
		ZZLog(b)
		
		//`Range` instances can represent an empty interval, unlike `ClosedRange`.
		let empty = 0.0..<0.0
		ZZLog(empty)
	}
	
	func useableMethod() {
		//contains
		let a : Range = 0.0..<5.0
		let blooen1 = a.contains(3.9)
		ZZLog(blooen1)
		//isEmpty
		let empty = 0.0..<0.0
		let blooen2 = empty.isEmpty
		ZZLog(blooen2)
	}
	
	//去重合部分
	func clamped() {
		let x: Range = 0..<20
		print(x.clamped(to: 10..<1000))
		// Prints "10..<20"
	
		/// If the two ranges do not overlap, the result is an empty range within the
		/// bounds of `limits`.
		let y: Range = 0..<5
		print(y.clamped(to: 10..<1000))
		// Prints "10..<10"
	}
	
	func property() {
		let a : Range = 0..<5
		ZZLog(a.upperBound)
		ZZLog(a.lowerBound)
	}
}
